{extend name="public:member" /}
{block name="content"}	
<div class="page-header">
	<h1>	
		{$breadcrumb1}
		<small>
			<i class="ace-icon fa fa-angle-double-right"></i>
			{$breadcrumb2}
		</small>
	</h1>
</div>
<div class="page-header">
	<a href="{:url('Item/add')}" class="btn btn-primary">新增</a> 
	 
	<span class="btn btn-primary copy">复制</span>
</div>	

<table class="table table-striped table-bordered table-hover search-form">
	<thead>
		<th><input name="title" type="text" placeholder="标题" value="{:input('title')}" /></th>
		<th>    				
			<select name="cat">
				<option value="">-所有分类-</option>
				
				{volist name="category" id="cat"}
					<option {if condition="input('cat') eq $cat['id']"} selected="selected"{/if} value="{$cat.id}">{$cat.title_show}</option>
				{/volist}
				
				
			</select>
		</th>
		<th>
			<a class="btn btn-primary" href="javascript:;" id="search" url="{:url('Item/index')}">查询</a>
		</th>
	</thead>
</table>
	
<div class="row">
	<div class="col-xs-12">	
		<div>
			<table class="table table-striped table-bordered table-hover">
				<thead>
					<tr>		
						<th class="center">
							<label>
								<input type="checkbox" class="ace check-all" />
								<span class="lbl"></span>
							</label>
						</th>									
						<th>缩略图</th>
						<th>标题</th>
						<th>分类</th>
						<th>地点</th>
						
						<th>所需金额(元)</th>
						<th>报名人数</th>
						<th>名额</th>
						<th>报名时间</th>
						<th>活动时间</th>		
						<th>状态</th>
						<th>操作</th>	
					</tr>
				</thead>
				<tbody>
						
						{volist name="list" id="item" empty="$empty"}
						<tr>
							<td class="center">
							<label>
								<input class="ace ids" type="checkbox" name="id[]" value="{$item.id}"/>
								<span class="lbl"></span>
							</label>
							</td>	
							<td>
							 {if condition="!empty($item['image'])"}									
							 	<img src="IMG_ROOT{$item.image|resize=50,50}" />	
							 {else /}
							 	<img src="__PUBLIC__/image/no_image_50x50.jpg" />	
							 {/if}						 
							</td>
							<td>{$item.title}</td>
							<td><?php echo $service->get_item_category_info($item['cid'],'name'); ?></td>
							<td>{$item.location}</td>
							<td>{$item.price}</td>
							
							<td>{$item.join_num}</td>
							<td>
								{if condition="$item['total_num'] eq 0"}
									不限
								{else /}
									{$item.total_num}
								{/if}
								
							
							</td>
							<td>
								<?php if($item['start_apply_time']==0){echo '不限';}else{echo date('Y-m-d',$item['start_apply_time']);} ?>
								~								
								<?php if($item['end_apply_time']==0){echo '不限';}else{echo date('Y-m-d',$item['end_apply_time']);} ?>
							</td>
							<td>
								<?php if($item['start_time']==0){echo '不限';}else{echo date('Y-m-d',$item['start_time']);} ?>
								~								
								<?php if($item['end_time']==0){echo '不限';}else{echo date('Y-m-d',$item['end_time']);} ?>								
							</td>
							<td>
								{switch name="item.status"}
									{case value="1"}<a title="已审核"><span class="btn btn-xs btn-success"><i class="fa fa-check bigger-120"></i></span></a>{/case}
									{case value="0"}<a title="未审核"><span class="btn btn-xs btn-danger"><i class="fa fa-remove bigger-120"></i></span></a>{/case}
								{/switch}
							</td>
							<td>
								<div class="btn-group">
									<a class="btn btn-xs btn-info"  href='{:url("item/edit",array("id"=>$item["id"]))}'>
										<i class="fa fa-edit bigger-120"></i>
									</a>
									
								</div> 
								
								
								<a class="delete btn btn-xs btn-danger" href='{:url("item/del",array("id"=>$item["id"]))}' >
									<i class="fa fa-trash bigger-120"></i>
								</a>
							</td>
						</tr>
						{/volist}
						<tr>
							<td colspan="20" class="page">{$list->render()}</td>
						</tr>
						<tr>
							<td colspan="20">总计 {$list->total()|default="0"} </td>
						</tr>
				</tbody>
				
			</table>
		</div>
	</div>
</div>
{/block}
{block name="javascript"}
<script>
$(function(){
	
	$("#search").click(function () {
        var url = $(this).attr('url');
        var query = $('.search-form').find('input,select').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
        query = query.replace(/^&/g, '');
        if (url.indexOf('?') > 0) {
            url += '&' + query;
        } else {
            url += '?' + query;
        }
        window.location.href = url;
    });
	
	$('.copy').click(function(){
		$.ajax({
		url: "{:url('Item/copy_item')}",
		type: 'post',
		data: $('input:checked'),
		dataType: 'json',
		beforeSend: function() {
			$('.copy').attr('disabled', true);
			$('.copy').after('<span class="wait">&nbsp;<img src="__PUBLIC__/image/loading.gif" alt="" /></span>');
		},	
		complete: function() {
			$('.copy').attr('disabled', false); 
			$('.wait').remove();
		},			
		success: function(json) {
			$('.warning, .error').remove();
					
			if (json['redirect']) {				
				
				location = json['redirect']
								
			} 
		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert('复制失败');
		}
	});	
	});
});		
</script>
{/block}